package com.naiterui.ehp.bs.cms.modules.recommend.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.naiterui.ehp.bp.constants.SwaggerTag;
import com.naiterui.ehp.bp.security.annotation.SysLog;
import com.naiterui.ehp.bp.security.utils.SecurityUtils;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bs.cms.common.vo.PageParamsVO;
import com.naiterui.ehp.bs.cms.common.vo.PageVO;
import com.naiterui.ehp.bs.cms.modules.recommend.feign.IRecomFeignClient;
import com.naiterui.ehp.bs.cms.modules.recommend.service.IMedictionRecomAuditService;
import com.naiterui.ehp.bs.cms.modules.recommend.vo.RecomAuditConfigVO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * 处方审核开关
 *
 * @author guoyongxiang
 * @date 2019-06-18 15:15
 * @since 1.0.0
 */
@Api(tags = {SwaggerTag.CMS + SwaggerTag.RECOM})
@RestController
@RequestMapping("medication/recom")
public class MedicationRecomAuditController {

  @Autowired
  private IRecomFeignClient recomFeignClient;
  @Autowired
  private IMedictionRecomAuditService medictionRecomAuditService;

  @ApiOperation("处方审核开关操作记录")
  @SysLog("处方审核开关操作记录")
  @GetMapping("audit/config/list")
  @PreAuthorize("@p.check('medication:recom:audit:config:list')")
  public PageVO<RecomAuditConfigVO> list(PageParamsVO pageParamsVO) {
    return this.medictionRecomAuditService.queryPage(pageParamsVO);
  }

  @ApiOperation("处方审核开关设置")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "auditType", value = "审核类别(1:系统, 2:人工)", dataType = "int", paramType = "form", required = true),
      @ApiImplicitParam(name = "remark", value = "操作备注", dataType = "String", paramType = "form", required = true)
  })
  @SysLog("处方审核开关设置")
  @PostMapping("audit/config/set")
  @PreAuthorize("@p.check('medication:recom:audit:config:set')")
  public void setAuditConfig(Integer auditType, String remark) throws BusinessException {
    this.recomFeignClient.setAuditConfig(auditType, remark, SecurityUtils.getCurrentUser().getUsername());
  }

}
